﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using CommunitySystem.GuaZhiDuanLianService;

namespace CommunitySystem.PageView
{
    public partial class JSJYWindow : ChildWindow
    {
        private Emp_JYModel entity = new Emp_JYModel();
        private GuaZhiDuanLianServiceClient client = new GuaZhiDuanLianServiceClient();
        public JSJYWindow(Emp_JYModel model)
        {
            InitializeComponent();
            entity = model;
        }

        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            if (this.dpkDate.SelectedDate == null)
            {
                SilverlightMessageBoxLibrary.Message.ErrorMessage("请选择借用结束时间!");
                return;
            }
            entity.EndDate = this.dpkDate.SelectedDate.Value.ToString();
            if (!string.IsNullOrEmpty(entity.EndDate) && Convert.ToDateTime(entity.BeginDate) > Convert.ToDateTime(entity.EndDate))
            {
                SilverlightMessageBoxLibrary.Message.ErrorMessage("借调的结束时间不能早于开始时间!");
                return;
            }
          
            entity.Status = "借用结束";
            client.JYJSCompleted += new EventHandler<JYJSCompletedEventArgs>(client_JYJSCompleted);
            client.JYJSAsync(entity);
        }

        void client_JYJSCompleted(object sender, JYJSCompletedEventArgs e)
        {
            if (e.Result)
                SilverlightMessageBoxLibrary.Message.InfoMessage("操作成功!");
            else
                SilverlightMessageBoxLibrary.Message.InfoMessage("操作失败!");

            this.DialogResult = true;
        }
        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }
     
    }
}

